package org.lesson4_aop;

import org.junit.Test;
import org.lesson4_aop.service.proxy.EmployeeService;
import org.lesson4_aop.service.proxy.EmployeeServiceProxy;
import org.lesson4_aop.service.proxy.IEmployeeService;
import org.lesson4_aop.service.stock.StockService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class ProxyTestor {

    @Test
    public void testProxy(){

        IEmployeeService employeeService1 = new EmployeeService();

        IEmployeeService employeeService = new EmployeeServiceProxy(employeeService1);

        employeeService.newDoc();//得到了增强

    }


    @Test
    public void testAop(){
        ApplicationContext context = new AnnotationConfigApplicationContext(ApplicationCf.class);

         org.lesson4_aop.service.hr.EmployeeService employeeService = (org.lesson4_aop.service.hr.EmployeeService) context.getBean("employeeService");

        employeeService.newDoc();

        StockService stockService = (StockService) context.getBean("stockService");

        stockService.inStock();

    }
}
